package com.fengye.security.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.fengye.security.demo.mapper.PermMapper;
import com.fengye.security.demo.model.Perm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author sky
 * @Email <mailto:fengyexjtu@126.com>
 * @Date 2020/12/29 14:38
 * @Description
 */

@Service
public class PermService {
    @Autowired
    private PermMapper permMapper;

    public List<Perm> list(){
        return permMapper.selectList(null);
    }

    public Perm findByUrl(String url){
        QueryWrapper<Perm> wrapper = new QueryWrapper<>();
        wrapper.eq("url", url);
        return permMapper.selectOne(wrapper);
    }

    public List<String> listUrls() {
        return this.list().stream().map(Perm::getUrl).collect(Collectors.toList());
    }
}
